package view.client;

import view.client.Console;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;

public class PanelBattle extends javax.swing.JPanel implements ActionListener, MouseListener  {
    private Console csl;
    private DefaultListModel modelSkill = new DefaultListModel();
    private DefaultListModel modelConsumable = new DefaultListModel();


    public PanelBattle(Console csl) {
        initComponents();
        loadSkill();
        this.csl = csl;
        comboAction.addActionListener(this);
        listAction.addMouseListener(this);
        jScrollPane1.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
			public void adjustmentValueChanged(AdjustmentEvent e){
			getTxtArea().select(getTxtArea().getHeight()+10000,0);
			}});
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        comboAction = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        listAction = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtArea = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        lblName = new javax.swing.JLabel();
        pbEnemyLife = new javax.swing.JProgressBar();
        pbEnemyEnergy = new javax.swing.JProgressBar();
        lblEnergia2 = new javax.swing.JLabel();
        lblVida1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        lblName2 = new javax.swing.JLabel();
        pbLife = new javax.swing.JProgressBar();
        pbEnergy = new javax.swing.JProgressBar();
        lblEnergia4 = new javax.swing.JLabel();
        lblVida3 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(153, 153, 153));

        comboAction.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Habilidades", "Items" }));

        listAction.setBackground(new java.awt.Color(51, 51, 51));
        listAction.setForeground(new java.awt.Color(255, 255, 255));
        jScrollPane2.setViewportView(listAction);

        txtArea.setBackground(new java.awt.Color(255, 204, 102));
        txtArea.setColumns(20);
        txtArea.setEditable(false);
        txtArea.setLineWrap(true);
        txtArea.setRows(5);
        txtArea.setBorder(null);
        jScrollPane1.setViewportView(txtArea);

        jPanel3.setBackground(new java.awt.Color(102, 153, 255));

        lblName.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblName.setText("Nome");

        lblEnergia2.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblEnergia2.setText("Energia");

        lblVida1.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblVida1.setText("Vida");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblVida1, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(lblEnergia2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pbEnemyEnergy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pbEnemyLife, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(lblName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pbEnemyLife, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblVida1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblEnergia2)
                    .addComponent(pbEnemyEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(102, 153, 255));

        lblName2.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblName2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblName2.setText("Nome");

        lblEnergia4.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblEnergia4.setText("Energia");

        lblVida3.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblVida3.setText("Vida");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblVida3, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                    .addComponent(lblEnergia4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pbEnergy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pbLife, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)))
            .addComponent(lblName2, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(lblName2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblVida3)
                    .addComponent(pbLife, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblEnergia4)
                    .addComponent(pbEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(comboAction, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(comboAction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboAction;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblEnergia2;
    private javax.swing.JLabel lblEnergia4;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblName2;
    private javax.swing.JLabel lblVida1;
    private javax.swing.JLabel lblVida3;
    private javax.swing.JList listAction;
    private javax.swing.JProgressBar pbEnemyEnergy;
    private javax.swing.JProgressBar pbEnemyLife;
    private javax.swing.JProgressBar pbEnergy;
    private javax.swing.JProgressBar pbLife;
    private javax.swing.JTextArea txtArea;
    // End of variables declaration//GEN-END:variables

    public Console getCsl() {
        return csl;
    }
    public void loadConsumable(){
        listAction.setModel(getModelConsumable());
    }
    public void loadSkill(){
        listAction.setModel(getModelSkill());
    }
    

    public javax.swing.JComboBox getComboAction() {
        return comboAction;
    }


    public javax.swing.JPanel getjPanel3() {
        return jPanel3;
    }

    public javax.swing.JPanel getjPanel5() {
        return jPanel5;
    }

    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    public javax.swing.JScrollPane getjScrollPane2() {
        return jScrollPane2;
    }

    public javax.swing.JLabel getLblEnergia2() {
        return lblEnergia2;
    }

    public javax.swing.JLabel getLblEnergia4() {
        return lblEnergia4;
    }

    public javax.swing.JLabel getLblName() {
        return lblName;
    }

    public javax.swing.JLabel getLblName2() {
        return lblName2;
    }

    public javax.swing.JLabel getLblVida1() {
        return lblVida1;
    }

    public javax.swing.JLabel getLblVida3() {
        return lblVida3;
    }

    public javax.swing.JList getListAction() {
        return listAction;
    }

    public javax.swing.JProgressBar getPbEnemyEnergy() {
        return pbEnemyEnergy;
    }

    public javax.swing.JProgressBar getPbEnemyLife() {
        return pbEnemyLife;
    }

    public javax.swing.JProgressBar getPbEnergy() {
        return pbEnergy;
    }

    public javax.swing.JProgressBar getPbLife() {
        return pbLife;
    }

    public javax.swing.JTextArea getTxtArea() {
        return txtArea;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(getComboAction())){     
            if (getComboAction().getSelectedIndex() == 0){
                getListAction().setModel(getModelSkill());
            }
            else if (getComboAction().getSelectedIndex() == 1){
                getListAction().setModel(getModelConsumable());
            }
            
        }
    }

    public DefaultListModel getModelSkill() {
        return modelSkill;
    }

    public DefaultListModel getModelConsumable() {
        return modelConsumable;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (listAction.isEnabled()){
             if(e.getClickCount() == 2){
                 int index = listAction.locationToIndex(e.getPoint());
                 ListModel dlm = listAction.getModel();
                 Object item = dlm.getElementAt(index);
                 listAction.ensureIndexIsVisible(index);
                 csl.inputedText("/"+item.toString());
            }
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }
}
